function Indexer(did, cid, indexes) {
	'use strict';
	var content = document.getElementById(cid);
	var drawer = document.getElementById(did);
	var indexes = indexes;
	var indexTops = [];
	
	/**
	 * 初始化目录
	 **/
	 var indexList = document.createElement('div');
	 indexList.className = 'indexList';
	 drawer.appendChild(indexList);
	for(var i = 0; i < indexes.length; i++) {
		var item = document.createElement('div');
		item.className = 'item';
		(function(top) {
			item.onclick = function() {
				onIndexClick(top);
			};
		})(indexes[i].top);
		var title = document.createElement('span');
		title.className = 'title';
		title.innerText = indexes[i].title;
		item.appendChild(title);
		indexList.appendChild(item);
		
		indexTops.push(item.clientHeight * i);
	}
	indexList.children[0].className = 'item checked';
	
	var scrollY = 0;
	var currentPos = 0;
	function calcCurrentPosisiton(scrollTop) {
		var deltaY = scrollTop - scrollY;
		scrollY = scrollTop;
		
		var pos = currentPos;
		if (deltaY > 0) {
			while (indexes[pos+1] && scrollTop >= indexes[pos+1].top) {
				pos++;
			}
		} else if (deltaY < 0) {
			while (indexes[pos] && scrollTop < indexes[pos].top) {
				pos--;
			}
		}
		
		if (pos != currentPos) {
			var child = indexList.children[currentPos];
			child.className = 'item';
			child = indexList.children[pos];
			child.className = 'item checked';
			currentPos = pos;
			
			var ch = indexList.clientHeight;
			var cs = indexList.scrollTop;
			var it = indexTops[currentPos];
			if (it < cs + 18) {
				indexList.scrollTop -= cs + 18 - it;
			} else if (it > cs + ch - 36) {
				indexList.scrollTop += it - (cs + ch - 36);
			}
		}
	}
	
	function onIndexClick(top) {
		content.scrollTop = top;
	}
	
	/**
	 * 监听当前滚动的距离
	 **/
	content.onscroll = function(e) {
		var scrollTop = e.currentTarget.scrollTop;
		setTimeout(function(){
			calcCurrentPosisiton(scrollTop);
		},100);
	};
}